package http

import (
	"geekbang-go-homework/week04/pkg/middleware"
	"net/http"
	"time"

	"google.golang.org/grpc/grpclog"
)

// ServerOption is http server option.
type ServerOption func(o *Server)

func WithHandler(handler http.Handler) ServerOption {
	return func(o *Server) {
		o.handler = handler
	}
}

// WithNetwork with server network.
func WithNetwork(network string) ServerOption {
	return func(s *Server) {
		s.network = network
	}
}

// WithAddress with server address.
func WithAddress(addr string) ServerOption {
	return func(s *Server) {
		s.address = addr
	}
}

// WithLog with server log
func WithLog(log grpclog.LoggerV2) ServerOption {
	return func(s *Server) {
		s.log = log
	}
}

// WithTimeout with server timeout
func WithTimeout(t time.Duration) ServerOption {
	return func(o *Server) {
		o.timeout = t
	}
}

// WithMiddleware with server middleware
func WithMiddleware(mid ...middleware.HandlerFunc) ServerOption {
	return func(o *Server) {
		o.middleware = mid
	}
}
